﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace GetData_TCPModbus
{
    public class LedDLL
    {
        [DllImport("BX_IV.dll")]
        public static extern int AddScreen(int nControlType, int nScreenNo,
        int nWidth, int nHeight, int nScreenType, int nPixelMode, int nDataDA,
           int nDataOE, int nRowOrder, int nFreqPar, string pCom, int nBaud,
           string pSocketIP, int nSocketPor, string pScreenStatusFile); //添加屏显

        [DllImport("BX_IV.dll")]
        public static extern int DeleteScreen(int nScreenNo);//删除屏显

        [DllImport("BX_IV.dll")]
        public static extern int SendScreenInfo(int nScreenNo, int nSendMode, int nSendCmd, int nOtherParam1);//发送相应命令到显示屏。 

        [DllImport("BX_IV.dll")]
        public static extern int AddScreenProgram(int nScreenNo, int nProgramType, int nPlayLength,
            int nStartYear, int nStartMonth, int nStartDay, int nEndYear, int nEndMonth, int nEndDay,
            int nMonPlay, int nTuesPlay, int nWedPlay, int nThursPlay, int bFriPlay, int nSatPlay, int nSunPlay,
            int nStartHour, int nStartMinute, int nEndHour, int nEndMinute); //向指定显示屏添加节目； 

        [DllImport("BX_IV.dll")]
        public static extern int DeleteScreenProgram(int nScreenNo, int nProgramOrd); //删除节目

        [DllImport("BX_IV.dll")]
        public static extern int DeleteScreenProgramArea(int nScreenNo, int nProgramOrd, int nAreaOrd);//删除区域

        [DllImport("BX_IV.dll")]
        public static extern int AddScreenProgramBmpTextArea(int nScreenNo, int nProgramOrd, int nX, int nY,
            int nWidth, int nHeight);//向指定显示屏指定节目添加图文区；

        [DllImport("BX_IV.dll")]
        public static extern int AddScreenProgramAreaBmpTextFile(int nScreenNo, int nProgramOrd, int nAreaOrd,
        string pFileName, int nShowSingle, string pFontName, int nFontSize, int nBold, int nFontColor,
            int nStunt, int nRunSpeed, int nShowTime); //向指定显示屏指定节目指定区域添加文件

        [DllImport("BX_IV.dll")]
        public static extern int DeleteScreenProgramAreaBmpTextFile(int nScreenNo, int nProgramOrd, int nAreaOrd, int nFileOrd); //删除指定显示屏指定节目指定图文区域的指定文件，删除文件成功后会将该文件信息删除

        [DllImport("BX_IV.dll")]
        public static extern int InitDLLResource(IntPtr AppHandle);

        [DllImport("BX_IV.dll")]
        public static extern int FreeDLLResource();

        public const int RETURN_ERROR_AERETYPE = 0xF7;//区域类型错误，在添加、删除图文区域文件时区域类型出错返回此类型错误。 
        public const int RETURN_ERROR_RA_SCREENNO = 0xF8;  //已经有该显示屏信息。如要重新设定请先DeleteScreen删除该显示屏再添加； 
        public const int RETURN_ERROR_NOFIND_AREAFILE = 0xF9; //没有找到有效的区域文件(图文区域)； 
        public const int RETURN_ERROR_NOFIND_AREA = 0xFA;  //没有找到有效的显示区域；可以使用AddScreenProgramBmpTextArea添加区域信息。 
        public const int RETURN_ERROR_NOFIND_PROGRAM = 0xFB;  //没有找到有效的显示屏节目；可以使用AddScreenProgram函数添加指定节目 
        public const int RETURN_ERROR_NOFIND_SCREENNO = 0xFC;  //系统内没有查找到该显示屏；可以使用AddScreen函数添加显示屏 
        public const int RETURN_ERROR_NOW_SENDING = 0xFD; //系统内正在向该显示屏通讯，请稍后再通讯；
        public const int RETURN_ERROR_OTHER = 0xFF; //其它错误； 
        public const int RETURN_NOERROR = 0; //没有错误 


        //------------------------------------------------------------------------------
        // 控制器类型
        public const int CONTROLLER_TYPE_3T = 0x10;
        public const int CONTROLLER_TYPE_3A = 0x20;
        public const int CONTROLLER_TYPE_3A1 = 0x21;
        public const int CONTROLLER_TYPE_3A2 = 0x22;
        public const int CONTROLLER_TYPE_3M = 0x30;

        public const int CONTROLLER_TYPE_4A1 = 0x0141;
        public const int CONTROLLER_TYPE_4A2 = 0x0241;
        public const int CONTROLLER_TYPE_4A3 = 0x0341;
        public const int CONTROLLER_TYPE_4AQ = 0x1041;
        public const int CONTROLLER_TYPE_4A = 0x0041;

        public const int CONTROLLER_TYPE_4M1 = 0x0142;
        public const int CONTROLLER_TYPE_4M = 0x0042;
        public const int CONTROLLER_TYPE_4MC = 0x0C42;
        public const int CONTROLLER_TYPE_4E = 0x0044;
        public const int CONTROLLER_TYPE_4C = 0x0043;
        public const int CONTROLLER_TYPE_4E1 = 0x0144;
        public const int CONTROLLER_TYPE_5M4 = 0x0452;
        public const int CONTROLLER_TYPE_5M2 = 0x0252;
        //------------------------------------------------------------------------------
        //==============================================================================
        // 控制器通讯模式
        public const int SEND_MODE_COMM = 0;
        public const int SEND_MODE_NET = 2;
        //==============================================================================

        //==============================================================================
        // 用户发送信息命令表
        public const int SEND_CMD_PARAMETER = 0xA1FF; //加载屏参数。
        public const int SEND_CMD_SCREENSCAN = 0xA1FE; //设置扫描方式。
        public const int SEND_CMD_SENDALLPROGRAM = 0xA1F0; //发送所有节目信息。
        public const int SEND_CMD_POWERON = 0xA2FF; //强制开机
        public const int SEND_CMD_POWEROFF = 0xA2FE; //强制关机
        public const int SEND_CMD_TIMERPOWERONOFF = 0xA2FD; //定时开关机
        public const int SEND_CMD_CANCEL_TIMERPOWERONOFF = 0xA2FC; //取消定时开关机
        public const int SEND_CMD_RESIVETIME = 0xA2FB; //校正时间。
        public const int SEND_CMD_ADJUSTLIGHT = 0xA2FA; //亮度调整。

        //==============================================================================
        
        public static string GetErrorMessage(string szfunctionName, int nResult)
        {
            string szResult;
            szResult = "执行函数：" + szfunctionName + "---返回结果：";
            switch (nResult)
            {
                case RETURN_ERROR_AERETYPE:
                    szResult += "区域类型错误，在添加、删除图文区域文件时区域类型出错返回此类型错误。";
                    break;
                case RETURN_ERROR_RA_SCREENNO:
                    szResult += "已经有该显示屏信息。如要重新设定请先DeleteScreen删除该显示屏再添加";
                    break;
                case RETURN_ERROR_NOFIND_AREAFILE:
                    szResult += "没有找到有效的区域文件(图文区域)";
                    break;
                case RETURN_ERROR_NOFIND_AREA:
                    szResult += "没有找到有效的显示区域可以使用AddScreenProgramBmpTextArea添加区域信息。";
                    break;
                case RETURN_ERROR_NOFIND_PROGRAM:
                    szResult += "没有找到有效的显示屏节目可以使用AddScreenProgram函数添加指定节目";
                    break;
                case RETURN_ERROR_NOFIND_SCREENNO:
                    szResult += "系统内没有查找到该显示屏可以使用AddScreen函数添加显示屏";
                    break;
                case RETURN_ERROR_NOW_SENDING:
                    szResult += "系统内正在向该显示屏通讯，请稍后再通讯";
                    break;
                case RETURN_ERROR_OTHER:
                    szResult += "其它错误";
                    break;
                case RETURN_NOERROR:
                    szResult += "函数执行/通讯成功";
                    break;
                case 0x01:
                    szResult += "通讯错误";
                    break;
                case 0x02:
                    szResult += "通讯错误";
                    break;
                case 0x03:
                    szResult += "通讯错误";
                    break;
                case 0x04:
                    szResult += "通讯错误";
                    break;
                case 0x05:
                    szResult += "通讯错误";
                    break;
                case 0x06:
                    szResult += "通讯错误";
                    break;
                case 0x07:
                    szResult += "通讯错误";
                    break;
                case 0x08:
                    szResult += "通讯错误";
                    break;
                case 0x09:
                    szResult += "通讯错误";
                    break;
                case 0x0A:
                    szResult += "通讯错误";
                    break;
                case 0x0B:
                    szResult += "通讯错误";
                    break;
                case 0x0C:
                    szResult += "通讯错误";
                    break;
                case 0x0D:
                    szResult += "通讯错误";
                    break;
                case 0x0E:
                    szResult += "通讯错误";
                    break;
                case 0x0F:
                    szResult += "通讯错误";
                    break;
                case 0x10:
                    szResult += "通讯错误";
                    break;
                case 0x11:
                    szResult += "通讯错误";
                    break;
                case 0x12:
                    szResult += "通讯错误";
                    break;
                case 0x13:
                    szResult += "通讯错误";
                    break;
                case 0x14:
                    szResult += "通讯错误";
                    break;
                case 0x15:
                    szResult += "通讯错误";
                    break;
                case 0x16:
                    szResult += "通讯错误";
                    break;
                case 0x17:
                    szResult += "通讯错误";
                    break;
                case 0x18:
                    szResult += "通讯错误";
                    break;
                case 0xFE:
                    szResult += "通讯错误";
                    break;
            }
            return szResult;
        }
        
    }
}
